package com.example.springboot.mapper;

import com.example.springboot.pojo.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface UserMapper {

    @Select("select * from user where id=#{id}")
    public User findById(Integer id);

    @Select("select * from user where username=#{username}")
    public User findByUserName(String username);

    @Insert("insert into user (username,password,create_datetime,update_datetime)" +
            " values(#{username},#{password},now(),now())")
    public void add(String username, String password);

    @Update("update user set username=#{username},email=#{email},nickname=#{nickname}" +
            "update_datetime=#{updateDatetime} where id=#{id}")
    void update(User user);

    @Update("update user set user_pic=#{avatarUrl},update_datetime=now() where id=#{id}")
    void updateAvater(String avatarUrl, Integer id);

    @Update("update user set password=#{newPwd},update_datetime=now() where id=#{id}")
    void updatePwd(String newPwd, Integer id);

}
